<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
         /* 
            需求：截取字符串中的某一段。
            D:\webs\web前端开发课程体系\第2阶段\day06_js数组常用函数进阶与String\vedio\hello.txt
            需求1：截取出 hello.txt
            需求2：截取出 txt
            需求3：截取出 hello
         */
        const str1 = "abcdef";
        console.log(str1.substring(1));
        console.log(str1.substring(1,5));//不包含尾部的
        //如果任一参数小于 0 或为 NaN，则被当作 0。就会被当作0，结果就是abcdef
        console.log(str1.substring(-2));

        const anyString = "Mozilla";

        console.log(anyString.substring(0,3));  //Moz
        //如果 indexStart 大于 indexEnd，则 substring 的执行效果就像两个参数调换了一样
        console.log(anyString.substring(3,0));      //Moz
        console.log(anyString.substring(3,-3));     //Moz
        console.log(anyString.substring(3,NaN));    //Moz
        console.log(anyString.substring(-2,3));     //Moz
        console.log(anyString.substring(NaN,3));    //Moz
        console.log(anyString.substring(4,7));      //lla
        console.log(anyString.substring(7,4));      //lla
        //如果 indexStart 等于 indexEnd，substring 返回一个空字符串。
        console.log(anyString.substring(4,4));      // 啥都没有
        console.log(anyString.substring(0,6));      //Mozill
        console.log(anyString.substring(0,7));      //Mozilla
        console.log(anyString.substring(0,10));     //Mozilla

        // 提取文件最后的三个四个
        console.log(anyString.substring(anyString.length - 3));
        console.log(anyString.substring(anyString.length - 4));

        const filename = "D:\\webs\\web前端开发课程体系\\第2阶段\\day06_js数组常用函数进阶与String\\vedio\\hello.txt";
        console.log(filename);
        console.log(filename.substring(filename.indexOf("\.") + 1));
        console.log(filename.substring(filename.lastIndexOf("\\") + 1));
        console.log(filename.substring(filename.lastIndexOf("\\")+1,filename.indexOf("\.")));

        // 取出前后空格
        // trim() 方法会从一个字符串的两端删除空白字符
        // trimStart() 会去掉左侧空格
        // trimEnd() 会去掉右侧空格
        const greeting = '   Hello world!   ';
        console.log(greeting);
        console.log(greeting.trimStart());
        console.log(greeting.trim());
        console.log(greeting.trimEnd());

        //字符串转换为大小写
        const greeting2 = 'HeLLo World!';
        console.log(greeting2.toUpperCase());
        console.log(greeting2.toLowerCase());
    </script>
</head>
<body>
    
</body>
</html>